﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using MCMLXVII.Core.Common;
using System.ServiceModel;
using MCMLXVII.BackEnd.Services.Common.Messages;

#endregion

namespace MCMLXVII.BackEnd.Data.SystemDatabase
{
    public enum SystemParameterType
    {
        ParametersVarchar = 1,
        ParameterDatetime = 2,
        ParameterInt = 3,
        ParameterXML = 4,
        ParameterFloat = 5

    }

    public class SystemParameter
    {
        private string _Name;
        private SystemParameterType _Type;
        private string _ValueVarchar;
        private DateTime _ValueDateTime;
        private int _ValueInt;
        private XmlDocument _ValueXML;
        private float _ValueFloat;

        public SystemParameter(string Name, string Value)
        {
            _Type = SystemParameterType.ParametersVarchar;
            _Name = Name;
            _ValueVarchar = Value;
        }
        public SystemParameter(string Name, DateTime Value)
        {
            _Type = SystemParameterType.ParameterDatetime;
            _Name = Name;
            _ValueDateTime = Value;
        }
        public SystemParameter(string Name, int Value)
        {
            _Type = SystemParameterType.ParameterInt;
            _Name = Name;
            _ValueInt = Value;
        }
        public SystemParameter(string Name, XmlDocument Value)
        {
            _Type = SystemParameterType.ParameterXML;
            _Name = Name;
            _ValueXML = Value;
        }
        public SystemParameter(string Name, float Value)
        {
            _Type = SystemParameterType.ParameterFloat;
            _Name = Name;
            _ValueFloat = Value;
        }

        public string name
        {
            get { return _Name; }
        }

        public SystemParameterType Type
        {
            get { return _Type; }
        }
        public string ValueVarChar
        {
            get
            {
                if (_Type == SystemParameterType.ParametersVarchar)
                    return _ValueVarchar;
                else
                    throw new FaultException<BackendFault>(new BackendFault(BackendFaulType.Technical,Properties.Resources.BadType));
                
            }
        }
        public DateTime ValueDateTime
        {
            get
            {
                if (_Type == SystemParameterType.ParameterDatetime )
                    return _ValueDateTime;
                else
                    throw new FaultException<BackendFault>(new BackendFault(BackendFaulType.Technical,Properties.Resources.BadType));                    
            }
        }
        public int ValueInt
        {
            get
            {
                if (_Type == SystemParameterType.ParameterInt )
                    return _ValueInt;
                else
                    throw new FaultException<BackendFault>(new BackendFault(BackendFaulType.Technical,Properties.Resources.BadType));
            }
        }
        public XmlDocument ValueXML
        {
            get
            {
                if (_Type == SystemParameterType.ParameterXML )
                    return _ValueXML;
                else
                    throw new FaultException<BackendFault>(new BackendFault(BackendFaulType.Technical,Properties.Resources.BadType));                    
            }
        }
        public float ValueFloat
        {
            get
            {
                if (_Type == SystemParameterType.ParameterFloat)
                    return _ValueFloat;
                else
                    throw new FaultException<BackendFault>(new BackendFault(BackendFaulType.Technical,Properties.Resources.BadType));
            }
        }
    }

}